import 'package:flutter/material.dart';
import 'package:miapp/Components/CStore.dart';
import './jsFramework/jsFramework.dart';
import 'jsFramework/jsWidget/index.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MiniAppStore with ChangeNotifier {
  Map _data = {
    "list": [
      {"title": "11111"},
      {"title": "222222"},
    ]
  };

  getData(String key) {
    key = key.replaceAll("{{", "").replaceAll("}}", "");
    return _data[key];
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return IStore(
      providers: [
        ChangeNotifierProvider(
          create: (_) => MiniAppStore(),
        ),
      ],
      builder: (BuildContext context) {
        return _MyHomePageState();
      },
    );
  }
}

class _MyHomePageState extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    MiniApp();
   
    return Scaffold(
      appBar: AppBar(
        title: Text("111"),
      ),
      body:JsonWidget(
        json:{
          "tag":"Container",
          "attr":{
            "width":200,
            "height":200,
            "color":"#FF6600",
            "border":"1px #FF0000"
          }
        }
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          CMiniapp.evalJavascript("WX.main()");
        },
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
